package com.ruoyi.web.controller.danger;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.SysAnalysisUnit;
import com.ruoyi.system.service.SysAnalysisUnitService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 分析单元清单(SysAnalysisUnit)表控制层
 *
 * @author makejava
 * @since 2022-11-14 16:17:44
 */
@RestController
@RequestMapping("sysAnalysisUnit")
public class SysAnalysisUnitController extends BaseController {

    /**
     * 服务对象
     */

    @Resource
    private SysAnalysisUnitService sysAnalysisUnitService;

    /**
     * 分页查询
     *
     * @param sysAnalysisUnit 筛选条件
     * @return 查询结果
     */

    @GetMapping("/list")
    public TableDataInfo queryByPage(SysAnalysisUnit sysAnalysisUnit) {
        startPage();
        List<SysAnalysisUnit> sysAnalysisUnits = sysAnalysisUnitService.queryByPage(sysAnalysisUnit);
        return getDataTable(sysAnalysisUnits);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */

    @GetMapping("{id}")
    public ResponseEntity<SysAnalysisUnit> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.sysAnalysisUnitService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysAnalysisUnit 实体
     * @return 新增结果
     */

    @PostMapping("/create")
    public AjaxResult add(@RequestBody SysAnalysisUnit sysAnalysisUnit) {
        SysAnalysisUnit insert = this.sysAnalysisUnitService.insert(sysAnalysisUnit);
        return AjaxResult.success(insert);
    }

    /**
     * 编辑数据
     *
     * @param sysAnalysisUnit 实体
     * @return 编辑结果
     */

    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SysAnalysisUnit sysAnalysisUnit) {
        SysAnalysisUnit update = this.sysAnalysisUnitService.update(sysAnalysisUnit);
        return AjaxResult.success(update);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */

    @GetMapping("/delete")
    public AjaxResult deleteById(Integer id) {
        boolean b = sysAnalysisUnitService.deleteById(id);
        return AjaxResult.success(b);
    }

}

